package com.itheima.d1_arrays.bean;

/**
 * 方案一：让一个类型具备比较的能力，实现一个接口
 * 升序排序：this - o
 * 降序排序：o - this
 * 包装类型都会有一个compare方法用来比较大小，可以直接用
 */
public class Student implements Comparable<Student>{
    private String name;
    private double height;
    private int age;
    //重写Comparable接口的compareTo方法，定义排序的规则（什么数据的什么排序）
    @Override
    public int compareTo(Student o) {
        //让学生数组，排序时按照年龄的升序排序
        //this  o

        //升序： this - o
        //1.确定，要按照什么数据进行排序，比如年龄排序
        //2.获取this的年龄以及o的年龄进行相减

        //return this.age-o.age;
        //return Integer.compare(this.age, o.age);

        //按照身高升序排序
        //return (int) (this.height - o.height);//当差值为0.x  -0.x 强转为int会变成0
        /*if (this.height>o.height) {
            return 1;
        } else if (this.height < o.height) {
            return -1;
        } else {
            return 0;
        } */
        //升序
        //return Double.compare(this.height, o.height);
        //降序
        //return Double.compare(o.height, this.height);
        //比字符串，按照年龄的升序排序
        return this.name.compareTo(o.name);
    }


    public Student() {
    }

    public Student(String name, double height, int age) {
        this.name = name;
        this.height = height;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", height=" + height +
                ", age=" + age +
                '}';
    }


}
